<template>
    <div class="container" style="width:99%;margin-top:-25px;">
        <!-- 查询条件 -->
        <div class="query-box">
            <el-form :model="queryBox" status-icon ref="queryBox">
                <div class="schoolBoxCont">
                    <div class="schoolBoxContItem">
                        <el-form-item label prop="name">
                            <div class="schoolBoxContItemTitle">学校名称</div>
                            <div class="schoolBoxContItemInput">
                                <el-input clearable v-model="queryBox.name" placeholder="学校名称"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                    <div class="schoolBoxContItem">
                        <el-form-item label prop="name">
                            <div class="schoolBoxContItemTitle">联系电话</div>
                            <div class="schoolBoxContItemInput">
                                <el-input clearable v-model="queryBox.phone" placeholder="联系电话"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                    <div class="schoolBoxContItem">
                        <el-form-item label prop="name">
                            <div class="schoolBoxContItemTitle">大区经理</div>
                            <div class="schoolBoxContItemInput">
                                <el-select
                                    v-model="queryBox.belongToId"
                                    filterable
                                    placeholder="请选择"
                                    value-key="id"
                                    style="width: 100%;"
                                >
                                    <el-option
                                        v-for="item in userName"
                                        :key="item.id"
                                        :label="item.realName"
                                        :value="item.id"
                                    ></el-option>
                                </el-select>
                            </div>
                        </el-form-item>
                    </div>
                    <div class="schoolBoxContItem">
                        <!-- <el-form-item label prop="name">
                            <div class="schoolBoxContItemTitle">三方姓名</div>
                            <div class="schoolBoxContItemInput">
                                <el-input clearable v-model="queryBox.thirdName" placeholder="三方姓名"></el-input>
                            </div>
                        </el-form-item> -->
                        <div class="schoolBoxContItem">
                            <el-form-item label prop="name">
                                <div class="schoolBoxContItemTitle">三方姓名</div>
                                <div class="schoolBoxContItemInput">
                                    <el-select
                                        filterable
                                        v-model="queryBox.thirdName"
                                        clearable
                                        placeholder="请选择"
                                    >
                                        <el-option
                                            v-for="item in schoolTripartiteTypeOption"
                                            :key="item.key"
                                            :label="item.value"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </div>
                            </el-form-item>
                        </div>
                    </div>
                    <div class="schoolBoxContItem">
                        <el-form-item label prop="name">
                            <div class="schoolBoxContItemTitle">三级部门</div>
                            <div class="schoolBoxContItemInput">
                                <el-select
                                    v-model="queryBox.thirdLevelDepartment"
                                    clearable
                                    filterable
                                    @change="changeThree"
                                >
                                    <el-option
                                        v-for="item in threeDept"
                                        :key="item.id"
                                        :label="item.deptName"
                                        :value="item.id"
                                    ></el-option>
                                </el-select>
                            </div>
                        </el-form-item>
                    </div>
                    <div class="schoolBoxContItem">
                        <el-form-item label prop="name">
                            <div class="schoolBoxContItemTitle">是否报备</div>
                            <div class="schoolBoxContItemInput">
                                <el-select clearable filterable v-model="queryBox.isRecord">
                                    <el-option
                                        v-for="item in isRecord_type_options"
                                        :key="item.key"
                                        :label="item.value"
                                        :value="item.key"
                                    ></el-option>
                                </el-select>
                            </div>
                        </el-form-item>
                    </div>

                    <div class="schoolBoxContItem">
                        <el-form-item label prop="name">
                            <div class="schoolBoxContItemTitle">意向程度</div>
                            <div class="schoolBoxContItemInput">
                                <el-select clearable filterable v-model="queryBox.type">
                                    <el-option
                                        v-for="item in student_type_options"
                                        :key="item.key"
                                        :label="item.value"
                                        :value="item.key"
                                    ></el-option>
                                </el-select>
                            </div>
                        </el-form-item>
                    </div>
                    <div class="schoolBoxContItem">
                        <el-form-item label prop="name">
                            <div class="schoolBoxContItemTitle">审核状态</div>
                            <div class="schoolBoxContItemInput">
                                <el-select clearable filterable v-model="queryBox.auditStatus">
                                    <el-option
                                        v-for="item in school_audit_status_option"
                                        :key="item.key"
                                        :label="item.value"
                                        :value="item.key"
                                    ></el-option>
                                </el-select>
                            </div>
                        </el-form-item>
                    </div>
                    <div class="schoolBoxContItem">
                        <el-form-item label prop="name">
                            <div class="schoolBoxContItemTitle">所在地区：</div>
                            <div class="schoolBoxContItemInput" style="width:300px">
                                <el-cascader
                                    clearable
                                    style="width:100% !important"
                                    size="large"
                                    :options="options"
                                    v-model="selectedOptions"
                                ></el-cascader>
                            </div>
                        </el-form-item>
                    </div>
                    <div class="schoolBoxContItem">
                        <el-form-item label prop="name">
                            <div class="schoolBoxContItemTitle" style="width:115px">审核日期</div>
                            <div class="schoolBoxContItemInput" style="width:428px">
                                <el-date-picker
                                    v-model="auditDate"
                                    type="daterange"
                                    range-separator="至"
                                    start-placeholder="开始日期"
                                    end-placeholder="结束日期"
                                    :default-time="['00:00:00', '23:59:59']"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </div>
                        </el-form-item>
                    </div>
                </div>
            </el-form>
            <div class="from-btns">
                <kt-button
                    :label="$t('action.reset')"
                    perms="true"
                    type="primary"
                    @click="reset('queryBox')"
                />
                <kt-button
                    :label="$t('action.search')"
                    perms="true"
                    type="primary"
                    @click="get_subcentersearch"
                />
            </div>
        </div>
        <!-- 批量删除按钮 -->
        <div class="add-btns fl">
            <kt-button
                :label="$t('action.batchdistribution')"
                :disabled="this.selections.length === 0"
                :perms="btnBatchdistribution"
                type="primary"
                @click="handlebatchdistribution"
            />
            <!-- perms="directCampCenter:school:batchdistribution" -->
            <kt-button
                :label="$t('导出')"
                :perms="btnExport"
                type="primary"
                @click="handleExport"
                style="float:left;"
            />
            <!-- perms="directCampCenter:school:export" -->
            <kt-button
                :label="$t('action.batchDelete')"
                :perms="btnDelete"
                :size="size"
                type="danger"
                @click="handleBatchDelete"
                :disabled="this.selections.length === 0"
                style="float:left;"
            />
            <!-- perms="directCampCenter:school:delete" -->
            <kt-button
                label="移入客户公海"
                :perms="btnToCustomerSea"
                :size="size"
                type="danger"
                @click="handleBatchDelete2"
                :disabled="this.selections.length === 0"
                style="float:left;"
            />
            <!-- perms="directCampCenter:school:toCustomerSea" -->
        </div>
        <!-- <div class="fr">
      <kt-button
        :label="$t('action.download-tmpl')"
        type="primary"
        perms="directCampCenter:school:download"
        @click="downloadTmpl"
      ></kt-button>
      <kt-button
        :label="$t('action.batchimport')"
        type="primary"
        perms="directCampCenter:school:batchimport"
        @click="customerManagerImport"
      ></kt-button>
      <kt-button
        label="新增学校"
        type="primary"
        perms="directCampCenter:school:add"
        @click="handleNewADD"
      ></kt-button>
        </div>-->
        <!--表格内容栏-->
        <div class="btn">
            <StTable
                @selectionChange="selectionChange"
                class="table-width"
                directCampCenterschool
                width="400"
                :permsSee="tableBtnSee"
                :permsEdit="tableBtnEdit"
                :data="pageResult"
                :columns="columns"
                :loading="loading"
                @findPage="findPage"
                @changeSwitch="changeSwitch"
                @handleEdit="handleEdit"
                @handleSee="handleSee"
            ></StTable>
            <!-- permsSee="directCampCenter:school:see"
            permsEdit="directCampCenter:school:edit"-->
        </div>

        <!--批量分配-->
        <div class="batchdistribution-pop">
            <el-dialog :visible.sync="batchdistribution" :close-on-click-modal="false" width="30%">
                <el-row>
                    <el-col :span="24">
                        <span class="batchdistribution-pop-tit">客户分配</span>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <span class="checked-person">已经选择{{ selections.length }}位客户</span>
                    </el-col>
                </el-row>
                <el-form :inline="true" :model="addstuformData" class="demo-form-inline">
                    <el-row>
                        <el-col :span="24">
                            <el-row>
                                <el-col :span="6">
                                    <span class="tit">划分方式：</span>
                                </el-col>
                                <el-col :span="18">
                                    <el-select
                                        clearable
                                        v-model="deptmodeoptionsValue"
                                        placeholder="请选择"
                                        @change="deptmodeoptionsChange"
                                    >
                                        <el-option
                                            v-for="item in deptmodeoptions"
                                            :key="item.index"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-col>
                    </el-row>
                    <!-- <el-row
            style="margin-top:5%"
            v-if="isShowFlag == 1 || isShowFlag == 2"
          >
            <el-col :span="24">
              <el-row>
                <el-col :span="6">
                  <span class="tit">选择部门：</span>
                </el-col>
                <el-col :span="18">
                  <popup-tree-input
                    :data="deptData"
                    :props="deptTree"
                    :prop="deptinputValue"
                    :currentChangeHandle="handleTreeSelectChange3Add"
                  ></popup-tree-input>
                </el-col>
              </el-row>
            </el-col>
                    </el-row>-->
                    <el-row style="margin-top:5%" v-if="isShowFlag == 2">
                        <el-col :span="24">
                            <el-row>
                                <el-col :span="6">
                                    <span class="tit">人员选择：</span>
                                </el-col>
                                <el-col :span="18">
                                    <el-select
                                        clearable
                                        filterable
                                        v-model="AllotData.belongToId"
                                        placeholder="请选择"
                                    >
                                        <el-option
                                            v-for="item in deptuseroption"
                                            :key="item.id"
                                            :label="item.realName"
                                            :value="item.id"
                                        ></el-option>
                                    </el-select>
                                </el-col>
                            </el-row>
                        </el-col>
                    </el-row>
                </el-form>

                <span slot="footer" class="dialog-footer">
                    <el-button @click="batchdistribution = false">取 消</el-button>
                    <!-- <el-button type="primary" @click="batchdistributionsubmit">确 定</el-button> -->
                    <el-button
                        type="primary"
                        v-if="isShowFlag == 1"
                        @click="batchdistributionsubmitdept"
                    >确 定</el-button>
                    <el-button
                        type="primary"
                        v-if="isShowFlag == 2"
                        @click="batchdistributionsubmituser"
                    >确 定</el-button>
                </span>
            </el-dialog>
        </div>

        <!--导入-->
        <el-dialog
            :title="'批量导入'"
            width="30%"
            :visible.sync="uploadOem"
            :close-on-click-modal="false"
        >
            <el-form :model="form">
                <el-form-item>
                    <el-upload
                        ref="uploadExcel"
                        :action="uploadUrl"
                        :limit="limitNum"
                        :auto-upload="false"
                        accept=".xls"
                        :before-upload="beforeUploadFile"
                        :on-change="fileChange"
                        :on-exceed="exceedFile"
                        :on-success="handleSuccess"
                        :on-error="handleError"
                        :file-list="fileList"
                        :on-remove="handleRemove"
                    >
                        <el-button size="small" plain>选择文件上传</el-button>
                        <div slot="tip" class="el-upload__tip">只能上传xls(Excel97-2004)文件</div>
                    </el-upload>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button :size="size" @click.native="uploadOem = false">
                    {{
                    $t("action.cancel")
                    }}
                </el-button>
                <el-button :size="size" type="primary" @click.native="uploadFile">
                    {{
                    $t("立即上传")
                    }}
                </el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import KtButton from "@/views/Core/KtButton";
import StTable from "@/views/Core/StTable";
import CrmSwitch from "@/views/Core/CrmSwitch";
import { CodeToText } from "element-china-area-data";
import { baseUrl } from "@/utils/global";
import { regionDataPlus } from "element-china-area-data";
import Cookies from "js-cookie";
import axios from "axios";
export default {
    name: "DirectCampCenterSchool",
    components: {
        PopupTreeInput,
        StTable,
        KtButton,
        CrmSwitch
    },
    data() {
        return {
            isShowFlag: 0, //0:初始化部门、人员不显示  1:部门显示 2：人员显示
            size: "small",
            filters: {
                name: ""
            },
            uploadOem: false, //文件上传
            limitNum: 1, //上传最大个数
            form: {
                file: ""
            },
            userName: "",
            fileList: [],
            uploadUrl: baseUrl + "/file/upload", //文件上传地址
            downloadTmplUrl: baseUrl + "/template/schoolImportTemplate.xlsx", //模板下载地址
            // 查询条件
            student_data_from_options: [
                {
                    label: " ",
                    key: " "
                }
            ],
            student_type_options: [],
            student_progress_options: [],
            student_data_from_type_options: [],
            student_import_department: [],
            isLock: [
                {
                    value: "解锁",
                    label: "2"
                },
                {
                    value: "锁定",
                    label: "1"
                }
            ],

            student_level_cache_options: [
                {
                    key: " ",
                    value: " "
                }
            ],
            //   地区
            options: regionDataPlus,
            selectedOptions: [],
            createDateArr: [], // 创建时间数组
            trackingDateArr: [], //跟进时间数组
            schoolSectionArr: [], //学段数组
            queryBox: {
                name: "",
                contact: "",
                peopleNum: "",
                schoolSystem: "",
                type: "",
                duty: "",
                phone: "",
                thirdProportion: 0,
                thirdName: "",
                thirdPhone: "",
                thirdContractSignedDate: "",
                thirdContractEndDate: "",
                paymentSituation: "",
                feastNum: "",
                mettingNum: "",
                visitNum: "",
                thirdLevelDepartment: "",
                isRecord: ""
            },

            columns: [
                { type: "index", label: "序号", minWidth: 50 },
                { prop: "name", label: "学校名称", minWidth: 180 },
                { prop: "peopleNum", label: "学校人数", minWidth: 100 },
                { prop: "contact", label: "学校负责人", minWidth: 80 },
                { prop: "duty", label: "职位", minWidth: 80 },
                { prop: "phone", label: "手机", minWidth: 100 },
                { prop: "belongToName", label: "所属大区经理", minWidth: 100 },
                {
                    prop: "thirdProportion",
                    label: "三方分成比例",
                    minWidth: 100
                },
                { prop: "thirdName", label: "三方姓名", minWidth: 100 },

                { prop: "thirdPhone", label: "三方手机", minWidth: 100 },
                {
                    prop: "thirdContractSignedDate",
                    label: "三方合同签署时间",
                    minWidth: 120
                },
                {
                    prop: "thirdContractEndDate",
                    label: "三方合同到期时间",
                    minWidth: 120
                },
                { prop: "paymentSituation", label: "回款情况", minWidth: 100 },
                { prop: "feastNum", label: "宴请次数", minWidth: 100 },
                { prop: "mettingNum", label: "参会次数", minWidth: 100 },
                { prop: "visitNum", label: "拜访次数", minWidth: 100 },
                { prop: "isRecord", label: "是否报备", minWidth: 100 },
                { prop: "auditStatusStr", label: "审核状态", minWidth: 100 },
                { prop: "diqu", label: "地区", minWidth: 190 },
                {
                    prop: "createDate",
                    sortable: "true",
                    label: "创建时间",
                    minWidth: 140
                }
            ],
            pageRequest: { pageNum: 1, pageSize: 10 },
            pageResult: {
                content: []
            },
            batchdistribution: false, //显示批量分配弹窗
            selectionsLength: "",
            selections: [], //选中列表集合
            ids: [], //分配ID集合
            deptData: [], //部门树
            deptTree: {
                label: "deptName",
                children: "children"
            },
            deptinputValue: "",
            // 划分方式
            deptmodeoptions: [
                // {
                //   label: "分配至部门",
                //   value: "11"
                // },
                {
                    label: "分配至个人",
                    value: "9"
                }
            ],

            deptuseroption: [], //部门用户
            loading: false, // 加载标识
            addstuformData: {},
            deptmodeoptionsValue: "",
            deptId: Cookies.get("threeLevelDeptId"),
            AllotData: {
                assignType: 2,
                schoolIds: "",
                thirdLevelDepartment: "",
                belongToId: "",
                belong_to_type: ""
            },
            threeDept: [],
            isRecord_type_options: [
                {
                    key: "1",
                    value: "已报备"
                },
                {
                    key: "2",
                    value: "未报备"
                }
            ],
            userName: [],
            school_audit_status_option: [],
            dataType: this.$route.fullPath.indexOf("dataType=2") > -1 ? 2 : "", // 根据参数动态添加权限按钮
            btnBatchdistribution: "",
            btnDelete: "",
            btnExport: "",
            tableBtnEdit: "",
            tableBtnSee: "",
            auditDate: [],
            btnToCustomerSea: "",
            schoolTripartiteTypeOption: []
        };
    },
    beforeMount: function() {
        let dataType = "";
        if (this.$route.fullPath.indexOf("dataType=2") > -1) {
            dataType = 2;
        }
        this.$api.agent.myTripartiteList({ dataType: dataType }).then(res => {
            if (res.result == 2) {
                this.$message({ message: res.msg, type: "error" });
            } else {
                this.schoolTripartiteTypeOption = res.data;
            }
        });
    },
    methods: {
        transformRouteBtnParam() {
            if (this.dataType && this.dataType == 2) {
                this.btnBatchdistribution =
                    "directCampCenter:tz:school:batchdistribution";
                this.btnExport = "directCampCenter:tz:school::export";
                this.btnDelete = "directCampCenter:tz:school:delete";
                (this.btnToCustomerSea =
                    "directCampCenter:tz:school:toCustomerSea"),
                    (this.tableBtnEdit = "directCampCenter:tz:school:edit");
                this.tableBtnSee = "directCampCenter:tz:school:see";
            } else {
                this.btnBatchdistribution =
                    "directCampCenter:school:batchdistribution";
                this.btnExport = "directCampCenter:school:export";
                this.btnDelete = "directCampCenter:school:delete";
                this.btnToCustomerSea = "directCampCenter:school:toCustomerSea";
                this.tableBtnEdit = "directCampCenter:school:edit";
                this.tableBtnSee = "directCampCenter:school:see";
            }
        },
        // 获取分页数据
        findPage: function(data) {
            if (data !== null) {
                // this.loading = true;
                this.pageRequest = data.pageRequest;
            }
            //如果创建时间查询的时候选择了，给查询参数赋值
            if (this.createDateArr.length > 0) {
                this.queryBox.createDateStart = this.createDateArr[0];
                this.queryBox.createDateEnd = this.createDateArr[1];
            }
            //如果跟进时间查询的时候选择了，给查询参数赋值
            if (this.trackingDateArr.length > 0) {
                this.queryBox.trackingDateStart = this.trackingDateArr[0];
                this.queryBox.trackingDateEnd = this.trackingDateArr[1];
            }
            // 审核日期
            if (this.auditDate.length > 0) {
                this.queryBox.auditDateStart = this.auditDate[0];
                this.queryBox.auditDateEnd = this.auditDate[1];
            }
            // 跟进日期降序
            this.queryBox.orderName='tracking_date',
            this.queryBox.orderType='desc'
            this.queryBox.queryInterface = 1;
            this.queryBox.pageNum = this.pageRequest.pageNum;
            this.queryBox.pageSize = this.pageRequest.pageSize;
            if (this.schoolSectionArr.length > 0) {
                this.queryBox.schoolSection = this.schoolSectionArr.join(",");
            } else if (this.schoolSectionArr.length == 0) {
                this.queryBox.schoolSection = "";
            }
            let dataType = "";
            // 获取参数判断是否是商务拓展中心
            if (this.$route.fullPath.indexOf("dataType=2") > -1) {
                dataType = 2;
            }
            if (dataType == 2) {
                this.queryBox.dataType = 2;
            }
            this.$api.school
                .cusomerschoolList(this.queryBox)
                .then(res => {
                    if (res.result == 2) {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    } else {
                        let content = {
                            content: res.listSchoolInfo,
                            totalSize: res.total
                        };
                        this.pageResult = content;
                        this.pageResult.content.forEach(item => {
                            item.thirdProportion = item.thirdProportion + "%";
                            item.isRecord == 1
                                ? (item.isRecord = "已报备")
                                : (item.isRecord = "未报备");
                            // 去掉时间的时分秒
                            item.thirdContractSignedDate = /\d{4}-\d{1,2}-\d{1,2}/g.exec(
                                item.thirdContractSignedDate
                            );
                            item.thirdContractEndDate = /\d{4}-\d{1,2}-\d{1,2}/g.exec(
                                item.thirdContractEndDate
                            );
                            //转换地区
                            if (
                                (item.province == null && item.city == null) ||
                                (item.province == "null" && item.city == "null")
                            ) {
                                item.diqu = "";
                            } else {
                                item.diqu =
                                    CodeToText[item.province] +
                                    CodeToText[item.city] +
                                    CodeToText[item.area];
                            }

                            //转换来源
                            this.student_data_from_options.forEach(
                                type_item => {
                                    if (type_item.key == item.dataFrom) {
                                        item.dataFrom = type_item.value;
                                    }
                                }
                            );
                            // 转换三方=
                            // this.schoolTripartiteTypeOption.forEach(
                            //     type_item => {
                            //         if (type_item.key == item.thirdPatry) {
                            //             item.thirdPatry = type_item.value;
                            //         }
                            //     }
                            // );
                            
                            //转换客户类型
                            this.student_type_options.forEach(type_item => {
                                if (type_item.key == item.type) {
                                    item.type2 = item.type;
                                    item.type = type_item.value;
                                }
                            });

                            //转换客户进展
                            this.student_progress_options.forEach(type_item => {
                                if (type_item.key == item.progress) {
                                    item.progress = type_item.value;
                                }
                            });
                            // 获取方式对应
                            this.student_data_from_type_options.forEach(
                                progress_item => {
                                    if (
                                        progress_item.key == item.dataFromType
                                    ) {
                                        item.dataFromType = progress_item.value;
                                    }
                                }
                            );
                            // 审核状态  1: 未提交  2:审核中 3:审核通过  4:审核驳回
                            if (item.auditStatus == 1) {
                                item.auditStatusStr = "未提交";
                            }
                            if (item.auditStatus == 2) {
                                item.auditStatusStr = "审核中";
                            }
                            if (item.auditStatus == 3) {
                                item.auditStatusStr = "审核通过";
                            }
                            if (item.auditStatus == 4) {
                                item.auditStatusStr = "审核驳回";
                            }
                            if (item.auditStatus == 0) {
                                item.auditStatusStr = "审核通过";
                            }
                            // 转换学段
                            if (
                                item.schoolSection != "" &&
                                item.schoolSection != null
                            ) {
                                let schoolSection = item.schoolSection.split(
                                    ","
                                );
                                let sectionStr = "";
                                schoolSection.forEach(
                                    (schoolSection, index) => {
                                        this.student_level_cache_options.forEach(
                                            level_cache => {
                                                if (
                                                    level_cache.key ==
                                                    schoolSection
                                                ) {
                                                    sectionStr =
                                                        sectionStr +
                                                        level_cache.value +
                                                        ",";
                                                }
                                            }
                                        );
                                    }
                                );
                                item.schoolSection = sectionStr.substring(
                                    0,
                                    sectionStr.lastIndexOf(",")
                                );
                            }
                        });
                        this.loading = false;
                    }
                })
                .then(data != null ? data.callback : "");
        },
        // 搜索
        get_subcentersearch() {
            this.loading = true;
            this.queryBox.province = this.selectedOptions[0];
            this.queryBox.city = this.selectedOptions[1];
            this.queryBox.area = this.selectedOptions[2];
            this.pageRequest.pageNum = 1;
            this.findPage(null);
        },
        // 客户类型
        get_student_type() {
            this.student_type_options = JSON.parse(
                localStorage.getItem("schoolType")
            );
            this.school_audit_status_option = JSON.parse(
                localStorage.getItem("schoolAuditStatus")
            );
        },

        // 客户来源
        get_student_data_from() {
            this.student_data_from_options = JSON.parse(
                localStorage.getItem("schoolSource")
            );
        },

        // 获取方式
        get_student_data_from_type() {
            this.student_data_from_type_options = JSON.parse(
                localStorage.getItem("schoolDataFromType")
            );
        },

        // 客户进展
        get_student_progress() {
            this.student_progress_options = JSON.parse(
                localStorage.getItem("schoolProgress")
            );
        },

        student_progress_change(value) {
            this.queryBox.student_progressValue = value.toString();
        },

        // 学段
        get_level_cache() {
            this.student_level_cache_options = JSON.parse(
                localStorage.getItem("schoolSection")
            );
        },

        // 重置
        reset(queryBox) {
            this.findPage(null);
            this.$refs.queryBox.resetFields();
            this.queryBox.name = "";
            this.queryBox.phone = "";
            this.queryBox.contact = "";
            this.queryBox.peopleNum = "";
            this.queryBox.schoolSystem = "";
            this.queryBox.type = "";
            this.queryBox.duty = "";
            this.queryBox.phone = "";
            this.queryBox.thirdProportion = 0;
            this.queryBox.thirdName = "";
            this.queryBox.thirdPhone = "";
            this.queryBox.thirdContractSignedDate = "";
            this.queryBox.thirdContractEndDate = "";
            this.queryBox.paymentSituation = "";
            this.queryBox.feastNum = "";
            this.queryBox.mettingNum = "";
            this.queryBox.visitNum = "";
            this.queryBox.selectedOptions = [];
            this.queryBox.province = "";
            this.queryBox.thirdLevelDepartment = "";
            this.queryBox.belongToId = "";
            this.selectedOptions = [];
            this.queryBox.city = "";
            this.queryBox.area = "";
            this.queryBox.isRecord = "";
            this.queryBox.thirdPatry = "";
            this.queryBox.auditStatus = "";
            this.pageRequest.pageNum = 1;
            this.auditDate = [];
            this.queryBox.auditDateStart = "";
            this.queryBox.auditDateEnd = "";
        },
        // 批量分配
        handlebatchdistribution(params) {
            this.batchdistribution = true;
            this.ids = [];
            let idstu = this.selections.map(item => item.id);
            this.ids = idstu;
            this.deptmodeoptionsValue = "";
            this.deptinputValue = "";
            this.deptuseroptionValue = "";
            this.isShowFlag = 0;
            this.AllotData.belongToId = "";
            this.get_dept_user();
        },

        // 批量分配提交
        batchdistributionsubmit() {
            this.AllotData.schoolIds = this.ids;
            this.$api.school.schoolAssign(this.AllotData).then(res => {
                if (res.result === 1) {
                    this.$message({ message: res.msg, type: "success" });
                    this.batchdistribution = false;
                    this.findPage(null);
                } else {
                    this.batchdistribution = false;
                    this.$message({ message: res.msg, type: "error" });
                }
            });
        },
        // 批量分配提交分配到部门
        batchdistributionsubmitdept() {
            this.AllotData.schoolIds = this.ids;
            this.$api.school.schoolAssign(this.AllotData).then(res => {
                if (res.result === 1) {
                    this.$message({ message: res.msg, type: "success" });
                    this.batchdistribution = false;
                    this.findPage(null);
                } else {
                    this.batchdistribution = false;
                    this.$message({ message: res.msg, type: "error" });
                }
            });
        },
        batchdistributionsubmituser() {
            this.AllotData.schoolIds = this.ids;
            this.$api.school.schoolAssign(this.AllotData).then(res => {
                if (res.result === 1) {
                    this.$message({ message: res.msg, type: "success" });
                    this.batchdistribution = false;
                    this.findPage(null);
                } else {
                    this.$message({ message: res.msg, type: "error" });
                }
            });
        },
        // 批量删除
        handleBatchDelete() {
            let schids = this.selections.map(item => item.id);
            console.log(this.ids);
            this.$confirm(
                "确认删除" + this.selections.length + "个客户吗？",
                "提示",
                {}
            ).then(() => {
                this.editLoading = true;
                this.$api.school
                    .schoolDelete({
                        schoolIds: this.ids,
                        dateType: 1
                    })
                    .then(res => {
                        if (res.result == 1) {
                            this.$message({
                                message: res.msg,
                                type: "success"
                            });
                            this.findPage(null);
                        } else {
                            this.$message({ message: res.msg, type: "error" });
                        }
                    });
            });
        },
        // 批量删除
        handleBatchDelete2() {
            let schids = this.selections.map(item => item.id);
            this.$confirm(
                "确认将" + this.selections.length + "个客户移入到公海吗？",
                "提示",
                {}
            ).then(() => {
                this.editLoading = true;
                this.$api.school
                    .removeTo({
                        schoolIds: this.ids
                        // dateType: 4
                    })
                    .then(res => {
                        if (res.result == 1) {
                            this.$message({
                                message: "删除成功",
                                type: "success"
                            });
                            this.findPage(null);
                        } else {
                            this.$message({
                                message: "删除失败",
                                type: "errory"
                            });
                        }
                    });
            });
        },

        // 解锁锁定
        changeSwitch: function(data) {
            this.$api.school
                .schoolInfoLock({
                    schoolId: data.row.id,
                    isLock: data.row.isLock
                })
                .then(res => {
                    if (res.result == 1) {
                        this.$message({ message: res.msg, type: "success" });

                        //执行查询接口，刷新列表信息
                        this.findPage();
                        // this.queryBox.queryInterface=1;
                        // this.queryBox.pageNum = this.pageRequest.pageNum;
                        // this.queryBox.pageSize = this.pageRequest.pageSize
                        // this.$api.school
                        // .cusomerschoolList(this.queryBox).then(res => {
                        //   this.pageResult.content=res.listSchoolInfo;
                        // })
                        // .then(data != null ? data.callback : "");
                    } else {
                        this.$message({ message: res.msg, type: "error" });
                    }
                });
        },

        // 批量导入
        customerManagerImport: function() {
            this.uploadOem = true;
            if (this.form.file != "") {
                this.$refs.uploadExcel.clearFiles();
                this.form.file = "";
            }
        },
        // 文件超出个数限制时的钩子
        exceedFile(files, fileList) {
            fileList.push(files);
            this.$notify.warning({
                title: "警告",
                message: `只能选择 ${
                    this.limitNum
                } 个文件，当前共选择了 ${files.length + fileList.length} 个`
            });
        },
        // 文件状态改变时的钩子
        fileChange(file, fileList) {
            this.form.file = file.raw;
        },
        // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
        beforeUploadFile(file) {
            let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
            let size = file.size / 1024 / 1024;
            if ((extension !== "xlsx") & "xls") {
                this.$notify.warning({
                    title: "警告",
                    message: `只能上传Excel97-2004（即后缀是.xls）的文件`
                });
            }
        },
        // 文件上传成功时的钩子
        handleSuccess(res, file, fileList) {
            this.$refs.uploadExcel.clearFiles();
            this.form.file = "";
            this.$notify.success({
                title: "成功",
                message: `文件上传成功,数据处理中,稍后在我的消息中查看！`
            });
        },
        // 文件上传失败时的钩子
        handleError(err, file, fileList) {
            this.$notify.error({
                title: "错误",
                message: `文件上传失败`
            });
        },
        uploadFile() {
            let formData = new FormData();
            formData.append("file", this.form.file);
            let dataType = "";
            // 获取参数判断是否是商务拓展中心

            if (this.$route.fullPath.indexOf("dataType=2") > -1) {
                dataType = 2;
            }
            axios
                .post(this.uploadUrl, formData, {
                    "Content-Type": "multipart/form-data"
                })
                .then(res => {
                    if (res.data.result == 1) {
                        let path = res.data.fileUrl;
                        this.$api.school
                            .customerManagerImport({ path: path })
                            .then(res => {
                                if (res.result == 2) {
                                    this.$message({
                                        message: res.msg,
                                        type: "error"
                                    });
                                    this.handleError();
                                } else {
                                    this.$message({
                                        message: res.msg,
                                        type: "success"
                                    });
                                    this.handleSuccess();
                                }
                                this.uploadOem = false;
                                this.findPage(null);
                            });
                    } else {
                        this.handleError();
                    }
                });
        },
        // 删除上传列表操作
        handleRemove(file, fileList) {
            this.form.file = "";
        },

        // 下载模板
        downloadTmpl() {
            this.getSchoolTempl();
        },

        // 获取部门数据
        get_dept_data() {
            //deptType:1 部门类型 1 学生 2 学酷 3 网校 4 学校
            this.$api.dropdown.deptLevel3({ deptType: 4 }).then(res => {
                this.deptData = res.departmentInfoList;
            });
        },

        //划分方式 控制部门人员显示
        deptmodeoptionsChange(value) {
            if (value == 9) {
                this.isShowFlag = 2;
                this.AllotData.belong_to_type = 1; //个人
                this.AllotData.thirdLevelDepartment = 0; //清空
            } else if (value == 11) {
                this.isShowFlag = 1;
                this.AllotData.belong_to_type = 2; //部门
                this.AllotData.belongToId = 0;
            } else {
                this.isShowFlag = 0;
            }
        },

        // 点击部门
        handleTreeSelectChange3Add(data, node) {
            this.deptinputValue = data.deptName;
            this.deptId = data.id;
            this.AllotData.thirdLevelDepartment = data.id;
            this.AllotData.belongToId = "";
            this.get_dept_user();
        },

        // 获取部门用户
        get_dept_user() {
            // this.$api.dropdown
            //   .users({ userType: 3, threeLevelDeptId: this.deptId, accountStatus: 1 })
            //   .then(res => {
            //     this.deptuseroption = res.userInfoList;
            //   });
            this.$api.dropdown
                .users({
                    userType: 3,
                    deptType: 4,
                    accountStatus: 1,
                    isControlResource: 1
                })
                .then(res => {
                    if (res.result == 1) {
                        this.deptuseroption = res.userInfoList;
                    }
                });
        },

        // 查看客户档案
        handleSee: function(params) {
            this.dataForm = Object.assign({}, params.row);
            this.$router.push({
                path: "/Customerfile/School",
                query: {
                    id: this.dataForm.id
                }
            });
        },

        // 修改客户档案
        handleEdit: function(params) {
            this.dataForm = Object.assign({}, params.row);
            this.$router.push({
                path: "/Customerfile/EditSchool",
                query: {
                    id: this.dataForm.id,
                    recordInfoId: params.row.recordInfoId,
                    auditStatus: params.row.auditStatus
                }
            });
        },

        // 获取选中的表格数据
        selectionChange: function(params) {
            let selectionsLength = params.selections.length;
            this.selections = params.selections;

            this.ids = [];
            let idstu = this.selections.map(item => item.id);
            this.ids = idstu;
        },

        // 新增客户
        handleNewADD: function() {
            let dataType = "";
            // 获取参数判断是否是商务拓展中心
            if (this.$route.fullPath.indexOf("dataType=2") > -1) {
                dataType = 2;
            }
            this.$router.push({
                path: "/Customerfile/AddSchool",
                query: {
                    createType: "1",
                    dataType: dataType
                }
            });
        },
        // 销售人员远程搜索
        querySearchAsync2(queryString, callback) {
            let restaurants = [{}];
            let results = "";
            let threeId = JSON.parse(Cookies.get("threeLevelDeptId"));
            if (threeId == null) {
                this.$api.dropdown
                    .users({ userType: 3, deptType: 4 })
                    .then(res => {
                        for (let i of res.userInfoList) {
                            i.value = i.realName; //将想要展示的数据作为value
                        }
                        restaurants = res.userInfoList;
                        results = queryString
                            ? restaurants.filter(
                                  this.createFilter2(queryString)
                              )
                            : restaurants;
                        callback(results);
                    });
            } else {
                this.$api.dropdown
                    .users({
                        userType: 3,
                        deptType: 4,
                        threeLevelDeptId: this.deptId
                    })
                    .then(res => {
                        for (let i of res.userInfoList) {
                            i.value = i.realName; //将想要展示的数据作为value
                        }
                        restaurants = res.userInfoList;
                        results = queryString
                            ? restaurants.filter(
                                  this.createFilter2(queryString)
                              )
                            : restaurants;
                        callback(results);
                    });
            }
        },
        createFilter2(queryString) {
            return restaurant => {
                return (
                    restaurant.realName
                        .toLowerCase()
                        .indexOf(queryString.toLowerCase()) === 0
                );
            };
        },
        handleSelect2(item) {
            this.queryBox.belongToId = item.id;
        },
        // 获取导入部门
        get_student_importDepartment() {
            this.$api.user
                .optionsList({ codeType: "school_import_department" })
                .then(res => {
                    this.student_import_department = res.keyValueList;
                });
        },
        handleClearable(value) {
            if (this.userName == "") {
                this.queryBox.belongToId = "";
            }
        },
        //三级部门改变
        changeThree: function(value) {
            this.queryBox.thirdLevelDepartment = value;
        },
        // 获取三级部门
        get_threeDept() {
            var  deptType=''
            if (this.$route.fullPath.indexOf("dataType=2") > -1) {
                deptType = 5;
            }else{
                deptType = 4
            }
            this.$api.user.queryDepartmentListtz({deptLevel: 3,deptType:deptType}).then(res => {
                this.threeDept = res.departmentInfoList;
            });
            this.$api.dropdown
                .users({ userType: 3, deptType: deptType, accountStatus: 1 })
                .then(res => {
                    if (res.result == 1) {
                        this.userName = res.userInfoList;
                    }
                });
        },
        Proportion(val) {
            if (val != 0) {
                if (val > 100) {
                    this.$message({
                        message: "请输入正确的分成比例！",
                        type: "error"
                    });
                    this.queryBox.thirdProportion = 0;
                    return false;
                }
                this.queryBox.thirdProportion = val;
                this.isSffc = !this.isSffc;
            } else if (val == 0 || val > 100 || val == "") {
                this.isSffc = !this.isSffc;
                this.queryBox.thirdProportion = 0;
            }
        },
        // 导出
        handleExport() {
            axios({
                method: "get",
                url: baseUrl + "/schoolInfoExport/export",
                params: this.queryBox
            }).then(res => {
                window.open(res.request.responseURL);
            });
        }
    },
    mounted() {
        this.transformRouteBtnParam();
        this.get_student_type();
        this.get_student_data_from();
        this.get_student_data_from_type();
        this.get_student_progress();
        this.get_level_cache();
        this.get_student_importDepartment();
        this.get_threeDept();
    }
};
</script>
<style>
@import url("../../assets/queryBox.css");
</style>
<style lang="scss" scope>
.checked-person {
    font-weight: 500;
    display: inline-block;
    text-align: center;
    margin: 3% 0 3% 0;
}
.batchdistribution-pop-tit {
    font-size: 20px;
    font-weight: bold;
    display: inline-block;
    color: #303133;
}
.add-btns .el-button:nth-child(1) {
    margin-right: 10px;
}

.el-dialog__wrapper .el-form-item__content {
    margin-left: 0;
}
.demo-form-inline {
    width: 90%;
    margin: 0 auto;
    .el-dialog__body .el-input {
        width: 93% !important;
    }
    .el-select {
        width: 100% !important;
    }
    .tit {
        display: inline-block;
        margin-top: 10%;
    }
}
.el-row .el-col {
    margin-left: 0;
}
.add-btns .el-button:nth-child(1) {
    margin-right: 10px;
}
.second-contain-box {
    width: 95%;
    margin: 0 auto;
    .el-col {
        text-align: left;
        margin: 4px 0;
    }
    .el-row {
        margin: 0 0 !important;
    }
    .el-col i {
        font-style: normal;
        display: inline-block;
        // margin-top: 10%;
    }
}
.schoolBoxCont {
    margin: 5px 5px;

    .schoolBoxContItem {
        margin-right: 10px;
        float: left;
        .el-form-item__content {
            display: flex;
            flex-direction: row;
        }
        .schoolBoxContItemTitle {
            background: #f5f7fa;
            width: 115px;
            border: 1px solid #dcdfe6;
            border-top-left-radius: 4px;
            border-bottom-left-radius: 4px;
            line-height: 39px;
            border-right: none;
        }
        .schoolBoxContItemInput {
            width: 150px;
            line-height: 39px;
            .el-date-editor.el-input,
            .el-date-editor.el-input__inner {
                width: 100%;
            }
        }
    }
}
</style>
<style lang='scss'>
.batchdistribution-pop .el-dialog__header {
    padding: 0 0 0 0 !important;
}
.schoolBoxCont {
    margin: 5px 5px;

    .schoolBoxContItem {
        margin-right: 10px;
        float: left;
        .el-form-item__content {
            display: flex;
            flex-direction: row;
        }
        .schoolBoxContItemTitle {
            background: #f5f7fa;
            width: 115px;
            border: 1px solid #dcdfe6;
            border-top-left-radius: 4px;
            border-bottom-left-radius: 4px;
            line-height: 39px;
            border-right: none;
        }
        .schoolBoxContItemInput {
            width: 150px;
            line-height: 39px;
            .el-date-editor.el-input,
            .el-date-editor.el-input__inner {
                width: 100%;
            }
        }
    }
}
</style>
